package com.yang.controller;

import com.yang.model.User;
import com.yang.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Resource
    private UserService userService;


    @PostMapping("/login")
    public User login(String account, String password) {
        User user = userService.login(account, password);
        return user;
    }

    @PostMapping("/register")
    public Integer register(String account, String password, String verifyPassword) {
        Integer res = userService.register(account, password, verifyPassword);
        return res;
    }

    @GetMapping("/all")
    public List<Map<String, Object>> getAll() {
        return userService.getAll();
    }
}
